Skip to content

Fix phpstan/phpstan#13629: False report for 2.1.30 release "arrayValues.list" ("Parameter X of array_values is already a list, call has no effect")#5264

Merged
staabm merged 6 commits intophpstan:2.1.xfrom
phpstan-bot:create-pull-request/patch-60ym3w2
Mar 21, 2026
Merged

Fix phpstan/phpstan#13629: False report for 2.1.30 release "arrayValues.list" ("Parameter X of array_values is already a list, call has no effect")#5264
staabm merged 6 commits intophpstan:2.1.xfrom
phpstan-bot:create-pull-request/patch-60ym3w2

Conversation

@phpstan-bot
Copy link
Collaborator

Summary

Fixes a false positive where array_values() on a nested array with string keys was reported as "already a list, call has no effect". The issue occurred when an array was built using string keys via nested dim-fetch assignment like $arr[$outerKey][$stringKey] = $value, but PHPStan incorrectly inferred the inner array as a list.

Changes

  • Fixed AccessoryArrayListType::setExistingOffsetValueType() in src/Type/Accessory/AccessoryArrayListType.php to return ErrorType when the offset type cannot be an integer. Previously it unconditionally returned $this, preserving the list type even for string key assignments.
  • Added rule regression test in tests/PHPStan/Rules/Functions/data/bug-13629.php and tests/PHPStan/Rules/Functions/ArrayValuesRuleTest.php
  • Added NSRT test in tests/PHPStan/Analyser/nsrt/bug-13629.php

Root cause

AccessoryArrayListType::setExistingOffsetValueType() always returned $this, meaning it preserved the list accessory type regardless of the offset type being set. When the assign handler processed a nested array assignment like $data[$outerKey][$stringKey] = $value and the scope already tracked $data[$outerKey], it used setExistingOffsetValueType (instead of setOffsetValueType). The setOffsetValueType method correctly returned ErrorType for non-integer/non-null offsets, but setExistingOffsetValueType did not, causing the list type to be incorrectly preserved through the intersection type.

Test

The regression test reproduces the exact scenario from the issue: building a nested array in loops where the inner array uses string keys ($viewHelper['name']), then calling array_values() on it. The test verifies no arrayValues.list error is reported.

Fixes phpstan/phpstan#13629

@@ -0,0 +1,45 @@
<?php declare(strict_types = 1);

namespace Bug13629;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't add this file twice. Re-use it with a relative path like other test-cases do

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the full test suite that already completed successfully — all 11630 tests passed. Everything has been committed and pushed already.

@staabm staabm requested a review from VincentLanglet March 21, 2026 07:37
@VincentLanglet
Copy link
Contributor

I think we could even check it's a superTypeOf IntegerRange(0, null), no ?

VincentLanglet and others added 4 commits March 21, 2026 09:40
- Fixed AccessoryArrayListType::setExistingOffsetValueType to return ErrorType
  when the offset type is definitely not an integer, dropping the list accessory
- The root cause was that setExistingOffsetValueType unconditionally preserved
  the list type even when a string key was being set on the array
- Added regression test for phpstan/phpstan#13629 (rule test + NSRT)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@staabm staabm force-pushed the create-pull-request/patch-60ym3w2 branch from 51bc04b to 3e363d2 Compare March 21, 2026 08:40
@staabm staabm merged commit cd904bb into phpstan:2.1.x Mar 21, 2026
632 of 648 checks passed
@staabm staabm deleted the create-pull-request/patch-60ym3w2 branch March 21, 2026 08:52
staabm added a commit to staabm/phpstan-src that referenced this pull request Mar 21, 2026
…rrayValues.list" ("Parameter X of array_values is already a list, call has no effect") (phpstan#5264)"

This reverts commit cd904bb.
staabm added a commit that referenced this pull request Mar 21, 2026
…rrayValues.list" ("Parameter X of array_values is already a list, call has no effect") (#5264)" (#5268)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants